package com.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @author:王宇航
 * @create: 2022-11-30 17:28
 * @Description:
 */

@Component
public class sendEmail {
    @Autowired
    private JavaMailSender javaMailSender;
private String context ="<img src='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.mamecn.com%2Fuploadfile%2F2020%2F0119%2F20200119041045266.jpg&refer=http%3A%2F%2Fimg.mamecn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1672392437&t=019926ce913411590295adff5843aade'/>" +
        "<br/><h2>验证码：</h2>";
    public void send(String to,int code){
        MimeMessage message=javaMailSender.createMimeMessage();
        MimeMessageHelper messageHelper=new MimeMessageHelper(message);
        try {
            messageHelper.setFrom("1963919036@qq.com"+"(专业团队)");
            messageHelper.setTo(to);
            messageHelper.setSubject("欢迎欢迎");
            messageHelper.setText(context+code,true);
            javaMailSender.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}
